<template>
  <div class="login-container">
    <h1>天气预报系统-用户登录</h1>
    <el-form :model="loginForm" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="loginForm.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="loginForm.password" type="password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleLogin">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage } from 'element-plus';

const router = useRouter();
const loginForm = ref({
  username: '',
  password: ''
});

const handleLogin = () => {
  if (loginForm.value.username === 'admin' && loginForm.value.password === '123456') {
    localStorage.setItem('isLoggedIn', 'true');
    router.push('/location-weather');
  } else {
    ElMessage.error('用户名或密码错误');
  }
};
</script>

<style scoped>
.login-container {
  padding: 20px;
  text-align: center;
}
</style>